package se.vgregion.velocity.hook.regioncalendar.util;

import org.apache.abdera.Abdera;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.cache.CachedResponse;
import org.apache.abdera.protocol.client.cache.InMemoryCache;

import java.util.HashMap;

public class AbderaClientUtil {
	
	private static AbderaClientUtil _instance = null;
	private static AbderaClient _abaderaClient;
	
	protected AbderaClientUtil() {

        Abdera abdera = new Abdera();

        setAbaderaClient(
                new AbderaClient(abdera, new InMemoryCache(abdera, new HashMap<Object, CachedResponse>()) {
                    @Override
                    public CachedResponse get(Object key) {
                        return null;
                    }

                    @Override
                    protected void add(Object key, CachedResponse response) {

                    }
                }));

        _abaderaClient.setSocketTimeout(4000);
        _abaderaClient.setConnectionTimeout(4000);
    }

	/**
	 * @return The unique instance of this class.
	*/
	public static AbderaClientUtil getInstance() {
		if(null == _instance) {
			_instance = new AbderaClientUtil();
		}
		return _instance;
	}
	 
	public AbderaClient getAbaderaClient() {
		return _abaderaClient;
	}
	
	public static void setAbaderaClient(AbderaClient abaderaClient) {
		AbderaClientUtil._abaderaClient = abaderaClient;
	}
}